//https://leetcode.cn/problems/minimum-time-to-complete-trips/submissions/

class Solution {
public:
    long long minimumTime(vector<int>& time, int totalTrips) {
        sort(time.begin(), time.end());
        long long l = 0, r = 1LL * totalTrips * time[0];
        while(l + 1 < r) {
            long long mid = (l + r) / 2;
            long long cnt = 0;
            for(int i = 0; i < time.size(); i++) {
                cnt += mid / time[i];
            }
            if(cnt >= totalTrips) r = mid;
            else l = mid;
        }
        return r;
    }
};